/**
 * Copyright (c) 2015-2016, Michael Yang 杨福海 (fuhai999@gmail.com).
 *
 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nike.model.base;

import com.nike.model.core.JModel;
import com.nike.model.Metadata;
import com.nike.model.query.MetaDataQuery;

import java.util.List;
import java.math.BigInteger;

import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;

/**
 *  Auto generated by JPress, do not modify this file.
 */
@SuppressWarnings("serial")
public abstract class BaseProductcategory<M extends BaseProductcategory<M>> extends JModel<M> implements IBean {

	public static final String CACHE_NAME = "productcategory";
	public static final String METADATA_TYPE = "productcategory";

	public void removeCache(Object key){
		CacheKit.remove(CACHE_NAME, key);
	}

	public void putCache(Object key,Object value){
		CacheKit.put(CACHE_NAME, key, value);
	}

	public M getCache(Object key){
		return CacheKit.get(CACHE_NAME, key);
	}

	public M getCache(Object key,IDataLoader dataloader){
		return CacheKit.get(CACHE_NAME, key, dataloader);
	}

	public Metadata findMetadata(String key){
		return MetaDataQuery.findByTypeAndIdAndKey(METADATA_TYPE, getId(), key);
	}

	public List<Metadata> findMetadataList(){
		return MetaDataQuery.findListByTypeAndId(METADATA_TYPE, getId());
	}

	public M findFirstFromMetadata(String key,Object value){
		Metadata md = MetaDataQuery.findFirstByTypeAndValue(METADATA_TYPE, key, value);
		if(md != null){
			BigInteger id = md.getObjectId();
			return findById(id);
		}
		return null;
	}

	public Metadata createMetadata(){
		Metadata md = new Metadata();
		md.setObjectId(getId());
		md.setObjectType(METADATA_TYPE);
		return md;
	}

	public Metadata createMetadata(String key,String value){
		Metadata md = new Metadata();
		md.setObjectId(getId());
		md.setObjectType(METADATA_TYPE);
		md.setMetaKey(key);
		md.setMetaValue(value);
		return md;
	}

	@Override
	public boolean equals(Object o) {
		if(o == null){ 
			return false; 
			
		}
		if(!(o instanceof BaseProductcategory<?>)){
			return false;
			
		}

		BaseProductcategory<?> m = (BaseProductcategory<?>) o;
		if(m.getId() == null){
			
			return false;
			
		}

		return m.getId().compareTo(this.getId()) == 0;
	}

	public void setId(java.lang.Integer id) {
		set("id", id);
	}

	public java.math.BigInteger getId() {
		Object id = get("id");
		if (id == null)
			return null;

		return id instanceof BigInteger ? (BigInteger)id : new BigInteger(id.toString());
	}

	public void setParentId(java.lang.String parentId) {
		set("parent_id", parentId);
	}

	public java.lang.String getParentId() {
		return get("parent_id");
	}

	public void setName(java.lang.String name) {
		set("name", name);
	}

	public java.lang.String getName() {
		return get("name");
	}

	public void setMetaDescription(java.lang.String metaDescription) {
		set("metaDescription", metaDescription);
	}

	public java.lang.String getMetaDescription() {
		return get("metaDescription");
	}

	public void setMetaKeywords(java.lang.String metaKeywords) {
		set("metaKeywords", metaKeywords);
	}

	public java.lang.String getMetaKeywords() {
		return get("metaKeywords");
	}

	public void setOrderList(java.lang.String orderList) {
		set("orderList", orderList);
	}

	public java.lang.String getOrderList() {
		return get("orderList");
	}

	public void setPath(java.lang.String path) {
		set("path", path);
	}

	public java.lang.String getPath() {
		return get("path");
	}

	public void setCreateDate(java.lang.String createDate) {
		set("createDate", createDate);
	}

	public java.lang.String getCreateDate() {
		return get("createDate");
	}

	public void setModifyDate(java.lang.String modifyDate) {
		set("modifyDate", modifyDate);
	}

	public java.lang.String getModifyDate() {
		return get("modifyDate");
	}

}
